/******************** 变量 ********************/
$lv-select-icon-color-disabled: rgba($icon-color-secondary, 0.5) !default;
$lv-select-selection-background-color: $tag-item-bg-color !default; // TODO 后续替换为tag组件，废弃

@include colorState('.lv-select-wrapper', $select-color-state);

// -------- open ----------
.lv-select-trigger-open {
  &.lv-select-wrapper {
    border-color: $primary-color;
  }
}

// -------- wrapper ----------
.lv-select-wrapper {
  position: relative;
  display: flex;
  box-sizing: border-box;
  width: 100%;
  min-height: 0.32rem;
  font-size: $font-size-base;
  border-style: solid;
  border-width: $border-width-base;
  border-radius: $border-radius-md;

  lv-help-tooltip {
    display: inline-flex;
    align-items: center;
  }

  @include motion-state;

  .lv-select-main {
    display: flex;
    flex: 1;
    align-items: center;
    min-width: 0;
    padding: 0.03rem 0 0.03rem $padding-sm;
  }

  &:hover {
    .lv-select-clear.show {
      visibility: visible;
      opacity: 1;
    }

    .lv-select-clear.show + .lv-select-operation {
      opacity: 0;
    }
  }

  .lv-select-clear {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    display: flex;
    justify-content: center;
    width: 0.32rem;
    height: 0.3rem;
    visibility: hidden;
    opacity: 0;

    @include motion-state;

    .lv-select-clear-container {
      display: flex;
      align-items: center;
      height: 100%;
    }

    i {
      @include icon-size;
    }
  }

  .lv-select-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 0.3rem;
    height: 0.3rem;

    .lv-icon-loading {
      @include icon-size;
    }
  }

  .lv-select-operation {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 0.32rem;
    line-height: 0.32rem;
    text-align: center;

    @include motion-state;

    .lv-select-trigger-icon {
      color: $icon-color-secondary;
    }
  }
}

.lv-select-wrapper {
  &.disabled {
    color: nth(nth($select-color-state, 5), 4);
    background: $disabled-background;
    border-color: $border-color-disabled;

    .lv-icon-host {
      color: $lv-select-icon-color-disabled;
    }

    .lv-trigger-item {
      background-color: $tag-item-bg-color-disabled;

      .lv-trigger-text {
        color: $tag-item-color-disabled;
      }
    }

    .lv-trigger-more-text,
    .lv-trigger-less-text {
      color: $tag-item-more-color-disabled;
      background-color: $tag-item-bg-color-disabled;
      cursor: not-allowed;
    }

    .lv-select-placeholder {
      color: rgba($text-color-tertiary, 0.5);
    }
  }

  &.lv-select-trigger-simple {
    display: inline-flex;
    align-items: center;
    height: unset;
    min-height: auto;
    background-color: initial;
    border: none;

    .lv-select-main {
      flex: unset;
      padding: 0;
    }

    .lv-select-operation {
      width: $icon-size-base;
      margin-left: $margin-xs;
    }

    .lv-select-clear {
      top: 0.03rem;
      height: auto;
    }

    &:hover:not(.disabled),
    &.lv-select-trigger-open {
      color: $primary-color;

      .lv-select-operation {
        .lv-select-trigger-icon {
          color: $primary-color;
        }
      }
    }
  }
}

// ---------- placeholder -------------
.lv-select-placeholder {
  color: $text-color-tertiary;
}

// --------- multiple -----------
.lv-select-trigger-multiple {
  &.lv-select-wrapper {
    height: auto;
    position: relative;

    .lv-select-main {
      padding: 0 0 0 $padding-xs;
    }

    .lv-select-operation {
      height: 0.3rem;
      position: absolute;
      right: 0;
      top: 0;
    }
  }

  .lv-select-value {
    .lv-select-trigger-default {
      min-height: 0.3rem;
      margin-top: -$margin-sm;
      padding: 0.03rem 0;
      overflow-x: hidden;
      overflow-y: auto;
      padding-right: $padding-xl;

      @include component-scroll;
    }

    .lv-trigger-item {
      height: 0.24rem;
      line-height: $line-height-lg;

      &:not(:last-child) {
        margin-right: $margin-sm;
      }

      &.lv-row-model:last-child:not(:first-child) {
        visibility: hidden;
      }
    }
  }

  .lv-select-placeholder {
    margin-left: $margin-xs;
  }

  &:not(.disable) .lv-select-operation::before {
    position: absolute;
    top: 0;
    left: -0.1rem;
    z-index: 1000;
    width: 0.1rem;
    height: 100%;
    content: ' ';
  }

  .lv-select-trigger-wrap {
    flex-wrap: wrap;
  }
}

.lv-select-value {
  display: flex;
  align-items: center;
  width: 100%;
  overflow: hidden;
}

.lv-select-trigger-default {
  display: flex;
  align-items: center;
  height: 100%;
  overflow: hidden;

  .lv-trigger {
    white-space: nowrap;
  }

  .lv-trigger-item:not(:last-child) {
    margin-right: $margin-sm;
  }
}

// --------------- tag -----------------
.lv-trigger-item {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-top: $margin-sm;
  padding: 0 $padding-xs 0 $padding-sm;
  background-color: $lv-select-selection-background-color;
  border-radius: $border-radius-md;

  .lv-trigger-text {
    color: $text-color;
    word-break: break-word;

    &.lv-only-safari.lv-overflow.lv-overflow-blank {
      word-wrap: normal;
      word-break: normal;
    }
  }

  .lv-icon-host {
    width: 0.16rem;
    min-width: 0.16rem;
    height: 0.16rem;
    margin-left: $margin-xs;

    &:hover {
      color: $text-color-link;
    }
  }
}

.lv-trigger-more-text,
.lv-trigger-less-text {
  display: block;
  height: 0.24rem;
  margin-top: $margin-sm;
  padding: 0 $margin-sm;
  color: $text-color-link;
  line-height: $line-height-lg;
  background: $lv-select-selection-background-color;
  border-radius: $border-radius-md;
  flex-shrink: 0;

  &:hover {
    background-color: $tag-item-bg-color-hover;
  }
}

// -------------- form 校验处理 ----------------
.lv-form-control-has-error .lv-select.ng-invalid.ng-touched,
.lv-form-control-has-error .lv-select.ng-invalid.ng-dirty {
  .lv-select-wrapper {
    border-color: $error-color;
  }
}

.lv-form-control-has-error .lv-cascader.ng-invalid.ng-touched,
.lv-form-control-has-error .lv-cascader.ng-invalid.ng-dirty {
  .lv-select-wrapper {
    border-color: $error-color;
  }
}

// ----------- size -----------------
.lv-select-trigger-size-large {
  &.lv-select-wrapper {
    min-height: $height-lg;

    .lv-select-loading {
      height: 0.38rem;
    }

    .lv-select-operation {
      height: 0.38rem;
    }

    .lv-select-clear {
      height: 0.38rem;
    }
  }
}

.lv-select-trigger-size-small {
  &.lv-select-wrapper {
    min-height: $height-sm;
    font-size: $font-size-sm;

    .lv-select-operation {
      line-height: $line-height-base;
    }

    .lv-select-loading {
      height: 0.22rem;
    }
  }
}

// ------------ calc ---------------
.lv-trigger-item-calc-container {
  visibility: hidden;
  position: fixed;
  display: flex;
}
